package com.lxmes.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.base.domain.JcItembzinfo;
import com.lxmes.base.service.IJcItembzinfoService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 物料标准明细Controller
 *
 * @author 张志煜
 * @date 2022-11-24
 */
@RestController
@RequestMapping("/base/itembzinfo")
public class JcItembzinfoController extends BaseController
{
    @Autowired
    private IJcItembzinfoService jcItembzinfoService;

    /**
     * 查询物料标准明细列表
     */
    @PreAuthorize("@ss.hasPermi('base:itembzinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcItembzinfo jcItembzinfo)
    {
        startPage();
        List<JcItembzinfo> list = jcItembzinfoService.selectJcItembzinfoList(jcItembzinfo);
        return getDataTable(list);
    }

    /**
     * 导出物料标准明细列表
     */
    @PreAuthorize("@ss.hasPermi('base:itembzinfo:export')")
    @Log(title = "物料标准明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcItembzinfo jcItembzinfo)
    {
        List<JcItembzinfo> list = jcItembzinfoService.selectJcItembzinfoList(jcItembzinfo);
        ExcelUtil<JcItembzinfo> util = new ExcelUtil<JcItembzinfo>(JcItembzinfo.class);
        util.exportExcel(response, list, "物料标准明细数据");
    }

    /**
     * 获取物料标准明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:itembzinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(jcItembzinfoService.selectJcItembzinfoById(id));
    }

    /**
     * 新增物料标准明细
     */
    @PreAuthorize("@ss.hasPermi('base:itembzinfo:add')")
    @Log(title = "物料标准明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcItembzinfo jcItembzinfo)
    {
        return toAjax(jcItembzinfoService.insertJcItembzinfo(jcItembzinfo));
    }

    /**
     * 修改物料标准明细
     */
    @PreAuthorize("@ss.hasPermi('base:itembzinfo:edit')")
    @Log(title = "物料标准明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcItembzinfo jcItembzinfo)
    {
        return toAjax(jcItembzinfoService.updateJcItembzinfo(jcItembzinfo));
    }

    /**
     * 删除物料标准明细
     */
    @PreAuthorize("@ss.hasPermi('base:itembzinfo:remove')")
    @Log(title = "物料标准明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcItembzinfoService.deleteJcItembzinfoByIds(ids));
    }


    @Log(title = "物料管理", businessType = BusinessType.IMPORT)
    // @PreAuthorize("@ss.hasPermi('base:iteminfo:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<JcItembzinfo> util = new ExcelUtil<>(JcItembzinfo.class);
        List<JcItembzinfo> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = jcItembzinfoService.imporIteminfo(userList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<JcItembzinfo> util = new ExcelUtil<>(JcItembzinfo.class);
        util.importTemplateExcel(response, "物料数据");
    }

    /**
     * 删除物料标准明细
     */
    @Log(title = "物料标准明细")
    @GetMapping("/addbzItemInfo/{ids}")
    public AjaxResult addBZItemInfo(@PathVariable Long[] ids)
    {
        return AjaxResult.success(jcItembzinfoService.addBZItemInfo(ids));
    }
    @Log(title = "物料标准明细生成物料规则")
    @GetMapping("/addItemInfoGz/{ids}")
    public AjaxResult addItemInfoGz(@PathVariable Long[] ids)
    {
        return AjaxResult.success(jcItembzinfoService.addItemInfoGz(ids));
    }

    @DeleteMapping("/delAllItembzinfo")
    @Log(title = "删除全部物料标准信息")
    public AjaxResult delAllItembzinfo()
    {
        return AjaxResult.success(jcItembzinfoService.deleteAllItembzinfo());
    }

}
